/* 
Scenic Graphics Library
Copyright (C) 2007 Jouni Tulkki

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USApackage scenic;
*/

package scenic.toolkit;

import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.util.Vector;

import scenic.Graphics;
import scenic.toolkit.db.NodeArray;
import scenic.toolkit.db.SyncVector;
import scenic.toolkit.db.event.ChangeEvent;

public class CPanel extends CComponent {
	public CPanel() {
	}
	
	public void add(CComponent child) {
		super.addChild(child);
	}
	
	public CComponent getChildAt(Point2D p) {
		Vector<CComponent> children = getChildren();
		
		for(int i = children.size() - 1; i >= 0; i--) {
			if(children.elementAt(i).isInside(p))
				return children.elementAt(i);
		}
		return null;
	}
	
	public void changed(ChangeEvent event) {
		updateChildren();
	}
	
	private void updateChildren() {
		invalidate();
	}
	
	public void paint(Graphics g) {		
		Vector<CComponent> children = getChildren();
		
		for(int i = 0; i < children.size(); i++) {
			getScene().add(children.elementAt(i).getScene());
		}				
	}
}
